"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// @see https://docs.aircode.io/guide/functions/
const nodemailer_1 = require("nodemailer");
const utils_lib_js_1 = require("utils-lib-js");
const { service, host, port, user, pass } = process.env;
const EmailTransporter = {
    service,
    host,
    port,
    auth: {
        user,
        pass, // 发送方授权码
    },
};
class SendMail {
    constructor() {
        /* 发送邮件模块
         * @method    sendEmail
         * @for       SendMail
         * @param   {String} mail  用户邮箱
         * @param   {String} title  邮件标题
         * @param   {String} content  邮件内容
         * @return {Promise<res>}   是否发送成功
         */
        this.sendEmail = (opts) => {
            const { mail, title, content } = opts;
            this.mailOptions = {
                from: `消息来自 < ${user} >`,
                to: mail,
                subject: title,
                text: content,
            };
            return this.transporter.sendMail(this.mailOptions);
        };
        this.transporter = (0, nodemailer_1.createTransport)(EmailTransporter); //邮箱配置项
    }
}
const email = new SendMail();
async function default_1(params, _) {
    console.log('Received params:', params);
    const [err, msg] = await (0, utils_lib_js_1.catchAwait)(email.sendEmail(params));
    return err ?? msg;
}
exports.default = default_1;
